package gameframework;

import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.imageio.ImageIO;
import javax.swing.RepaintManager;

	public class ConGa {
		Graphics2D toancuc_g2d;
		//thoi gian chay 
		private static final long thoigian_khoitaoconga = Framework.secInNanosec *5;
		public static long thoigian_chaycachnhau = thoigian_khoitaoconga;
	public static long thoigianchaycuoicung = 0;
		//toa do x cua ga,vjt,ngan
		
		public  static  int x;
		// toa do y cua ga vit ngan
		
		public int y;
		
		//hinh cua ga,vit,ngan
		
		private BufferedImage ve_ga;
		//bien cua vit
		private BufferedImage ve_vit;
		private int chieu_rong_vit;
		private int chieu_cao_vit;
		//bien cua ngan
		private BufferedImage ve_ngan;
		private int chieu_rong_ngan;
		private int chieu_cao_ngan;
		private BufferedImage trung_ga;
		//khu vuc di chuyen cua ga,vit,ngan
		
		private int chieu_rong_ga;
		
		//
		
		public int chieu_cao_ga;
		
		//toc do duy chuyen ro trung
		
		public static  int tocdo_x;
		//toc do roi trung
		private int kx;
		private int ky;
		
		private int chieu_rong_trung;
		private int chieu_cao_trung;
		private boolean chay;
		// 
		public static boolean cho_chay; 
		//random
		Random ran=new Random();
		//static int h;
		 public ConGa(){
			Initialize();
			LoadContent();
			tocdo_x=2;
			kx=y;
			
		}
		 private void Initialize()
		    {   
		        // X coordinate of the landing area is at 46% frame width.
		       // x = (int)(Framework.frameWidth * 0.46);
		        // Y coordinate of the landing area is at 86% frame height.
		       // y = (int)(Framework.frameHeight * 0.88);
			
		    }
		private void LoadContent()
		{
			try
	     {//con ga
	         URL hinh_con_ga = this.getClass().getResource("/gameframework/resources/images/ga.png");
	         ve_ga = ImageIO.read(hinh_con_ga);
	         chieu_rong_ga = ve_ga.getWidth();
	         chieu_cao_ga=ve_ga.getHeight();
	         //con vit
	         URL hinh_con_vit = this.getClass().getResource("/gameframework/resources/images/vit.png");
	         ve_vit = ImageIO.read(hinh_con_vit);
	         chieu_rong_vit = ve_vit.getWidth();
	         chieu_cao_vit=ve_vit.getHeight();
	         //ve ngan
	         URL hinh_con_ngan = this.getClass().getResource("/gameframework/resources/images/ngan.png");
	         ve_ngan = ImageIO.read(hinh_con_ngan);
	         chieu_rong_ngan = ve_ngan.getWidth();
	         chieu_cao_ngan=ve_ngan.getHeight();
	         /*trung ga
	         URL hinh_trung = this.getClass().getResource("/gameframework/resources/images/egg.png");
	         trung_ga = ImageIO.read(hinh_trung);
	         chieu_rong_trung = trung_ga.getWidth();
	         chieu_cao_trung=trung_ga.getHeight();
	         */
	     }
	     catch (IOException ex) {
	         Logger.getLogger(RoTrung.class.getName()).log(Level.SEVERE, null, ex);
	     }
			
		}

		public void update()
		{
			
		/*int	h=1;
			if(gameTime-ConGa.thoigianchaycuoicung>=ConGa.thoigian_chaycachnhau&&cho_chay==false)
			{
	
			   quaphai();
			   ConGa.thoigianchaycuoicung = gameTime;
			  // cho_chay=true;
			}
			else if(gameTime>=Framework.secInNanosec*9*h&&cho_chay==true)
		{
			
				h++;
				quatrai();
				//ConGa.thoigianchaycuoicung = gameTime;
		 }*/
			
			
			if(x<=500)
				x+=tocdo_x;
			else if(x==Framework.frameWidth&&x>0){
			for(int i=0;i<4;i++)
				
				x-=tocdo_x;
			}
				
		
			
		}
		
public void Draw(Graphics2D g2d)
 {
		g2d.drawImage(ve_ngan,x+170,y,null);
	g2d.drawImage(ve_vit,x+88,y,null);
     g2d.drawImage(ve_ga, x, y, null);
 //    g2d.drawImage(trung_ga, x, ky+88, null);
   if(Canvas.keyboardKeyState(KeyEvent.VK_G))
   {
	   g2d.drawImage(ve_ga, x+250, y,null);
   }
   if(Canvas.keyboardKeyState(KeyEvent.VK_N))
   {
	   g2d.drawImage(ve_ngan, x+330, y,null);
   }
   if(Canvas.keyboardKeyState(KeyEvent.VK_V))
   {
	   g2d.drawImage(ve_vit, x+410, y,null);
   }
   
 }
//
	public void dram_ga(Graphics2D g2d)
	{
	
		g2d.drawImage(ve_ga, x+250, y, null);
		
	}
	//
	public  void quaphai()
	{
		
		
		 	x+=tocdo_x;
	
	
	
	}
	public   void quatrai()
	{
		x-=tocdo_x;
	}
	public void khoitaolai(int xx)
	{
		this.x=xx;
		ConGa.thoigian_chaycachnhau = thoigian_khoitaoconga;
		ConGa.thoigianchaycuoicung = 0;
		ConGa.tocdo_x=2;
		
	}
}
